
Partial Class UpdateProgressTest
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not Page.IsPostBack Then
        lblOutside.Text = Now.ToString
        lblReallyOutside.Text = Now.ToString
        lblEnd.text = Now.ToString

        Dim oSM As ScriptManager = New ScriptManager
        oSM.SupportsPartialRendering = True

        Me.form1.Controls.Add(oSM)

        'updatepanel 1================
        Dim oUP1 As UpdatePanel = New UpdatePanel
        oUP1.ID = "myup1"
        'oUP.ChildrenAsTriggers = True
        'oUP.RenderMode = UpdatePanelRenderMode.Inline
        oUP1.UpdateMode = UpdatePanelUpdateMode.Conditional

        AddUpdateProgress(oUP1)
        'Dim oP As System.Web.UI.UpdateProgress = New System.Web.UI.UpdateProgress
        'oP.AssociatedUpdatePanelID = oUP1.ID
        'oP.ProgressTemplate = New DNNProgressTemplate("<img src=""images/dnnanim.gif"">")
        'oUP1.ContentTemplateContainer.Controls.Add(oP)
        '==============================

        For i As Integer = 0 To div1.Parent.Controls.Count - 1
            If div1.Parent.Controls(i).ID = div1.ID Then
                div1.Parent.Controls.AddAt(i + 1, oUP1)
                oUP1.ContentTemplateContainer.Controls.Add(div1)
                Exit For
            End If
        Next


        'updatepanel 2================
        Dim oUP2 As UpdatePanel = New UpdatePanel
        oUP2.UpdateMode = UpdatePanelUpdateMode.Conditional
        oUP2.ID = "myup2"
        Me.form1.Controls.Add(oUP2)
        Dim oLbl As Label = New Label
        oLbl.ID = "lblTime"
        oLbl.Text = Now.ToString
        oUP2.ContentTemplateContainer.Controls.Add(oLbl)
        Dim oBtn As Button = New Button
        oBtn.ID = "btnPB"
        oBtn.Text = "PostBack"
        AddHandler oBtn.Click, AddressOf Button_Click
        oUP2.ContentTemplateContainer.Controls.Add(oBtn)

        AddUpdateProgress(oUP2)
        'oP = New System.Web.UI.UpdateProgress
        'oP.AssociatedUpdatePanelID = oUP2.id
        'oP.ProgressTemplate = New DNNProgressTemplate("<img src=""images/dnnanim.gif"">")
        ''oP.ProgressTemplate = New System.Web.UI.CompiledTemplateBuilder(
        'oUP2.ContentTemplateContainer.Controls.Add(oP)
        ''=============================

        'Me.form1.Controls.Add(oP)

        'End If
    End Sub

    Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim oLbl As Label = CType(Me.FindControl("lblTime"), Label)
        oLbl.Text = Now.ToString
        System.Threading.Thread.Sleep(2000)
    End Sub

    Public Class DNNProgressTemplate : Implements ITemplate
        Private m_sLiteral As String = "Please Wait..."
        Public Sub New(ByVal literal As String)
            m_sLiteral = literal
        End Sub

        Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
            container.Controls.Add(New LiteralControl(m_sLiteral))
        End Sub

    End Class

    Protected Sub btnout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnout.Click
        System.Threading.Thread.Sleep(2000)
    End Sub

    Private Sub AddUpdateProgress(ByVal up As UpdatePanel)
        Dim oP As System.Web.UI.UpdateProgress = New System.Web.UI.UpdateProgress
        oP.AssociatedUpdatePanelID = up.ID
        oP.ProgressTemplate = New DNNProgressTemplate("<img src=""images/dnnanim.gif"">")

        up.ContentTemplateContainer.Controls.Add(oP)
        'up.Page.Controls.Add(oP)
    End Sub
End Class
